layui.use(['form','layer','layedit','laydate','upload'],function(){
    var form = layui.form
    layer = parent.layer === undefined ? layui.layer : top.layer,
        laypage = layui.laypage,
        upload = layui.upload,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;


    form.on("submit(sub)",function(data){

        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        $.ajax({
            url: '../insurance/saveInsurance',
            type: 'post',
            async: false,
            data: {
                id:data.field.id,
                state:data.field.state
            },
            dataType: "json",
            success: function (res) {
                if (res.code == 200){
                    top.layer.close(index);
                    top.layer.msg("操作成功！",{icon: 6});
                    parent.location.reload();
                }else {
                    top.layer.msg(res.msg,{icon: 5});
                }
            }, error: function () {
                top.layer.msg("系统异常！", {icon: 6});
                top.layer.close(index);
            }
        });
        return false;
    });

});